package org.skatiger.jrove.spring.messages;

import java.io.Serializable;

import org.springframework.context.MessageSource;
import org.springframework.web.servlet.support.RequestContext;

public class SpringMessageBean implements Serializable{
    /**
     * 
     */
    private static final long serialVersionUID = -4955734712652382108L;
    
    private static final String[] EMPTY_ARRAY = new String[0];
    private RequestContext requestContext;

    public SpringMessageBean(RequestContext requestContext) {
        this.requestContext = requestContext;
    }

    protected MessageSource getMessageSource() {
        return requestContext.getMessageSource();
    }

    public String getMessage(String code) {
        return getMessage(code, EMPTY_ARRAY);
    }

    public String getMessage(String code, String arg1) {
        return getMessage(code, new String[] { arg1 });
    }

    public String getMessage(String code, String arg1, String arg2) {
        return getMessage(code, new String[] { arg1, arg2 });
    }

    public String getMessage(String code, String arg1, String arg2, String arg3) {
        return getMessage(code, new String[] { arg1, arg2, arg3 });
    }

    public String getMessage(String code, String arg1, String arg2,
            String arg3, String arg4) {
        return getMessage(code, new String[] { arg1, arg2, arg3, arg4 });
    }

    public String getMessage(String code, String... args) {
        return getMessageSource().getMessage(code, args,
                requestContext.getLocale());
    }
}
